home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************************
- *
- *
- * MacZoop - "the framework for the rest of us"
- *
- *
- *
- * ZDialog.h -- a dialog box
- *
- *
- *
- *
- *
- * © 1996, Graham Cox
- *
- *
- *
- *************************************************************************************************/
-
- #pragma once
-
- #ifndef __ZDIALOG__
- #define __ZDIALOG__
-
- #ifndef __ZWINDOW__
- #include "ZWindow.h"
- #endif
-
- // dialog item extra info record, used for edit field control and radio button groups. NOTE:
- // Do not rely on the format of this structure not changing. It is the place ZDialog stores
- // private item info and is likely to be extended in future.
-
- typedef struct
- {
- union
- {
- unsigned short flags; // bitfield for edit field behaviour
- short groupID; // group ID for radio button groups
- };
- union
- {
- long minValue; // for limited fields, the minimum value
- TEHandle mirrorTE; // for password fields, the mirror TE record
- // (n.b. p/w fields can't have limits [why would they?])
- };
- long maxValue; // -"-, the maximum value
- }
- DItemInfo, *DItemInfoPtr, **DItemInfoHdl;
-
- // flags bitfield used in above record:
-
- enum
- {
- editFieldIsDisabled = 1, // edit field is completely disabled
- editFieldSignedInteger = 2, // edit field only accepts numbers and - sign
- editFieldSignedFloat = 4, // as above plus decimal point character
- editFieldUnsignedInteger = 8, // accepts only numbers but not - sign
- editFieldUnsignedFloat = 16, // as above plus decimal point character
- editFieldHasMinValue = 32, // if int field, has an acceptable minimum val
- editFieldHasMaxValue = 64, // if int field, has an acceptable maximum val
- editFieldAlphabeticOnly = 128, // only accepts letters, not numbers
- editFieldHiddenChars = 256, // "password" style field hides input when typing
- editFieldHCMirrorAlloc = 0x8000, // the password mirror has been allocated
- efSignedLimitType = editFieldSignedInteger + editFieldHasMinValue + editFieldHasMaxValue,
- efUnsignedLimitType = editFieldUnsignedInteger + editFieldHasMinValue + editFieldHasMaxValue
- };
-
- // Password Fields, please note:
- // To establish a password field, set the flag <editFieldHiddenChars> (256) in your resource. When the
- // dialog is set up, this triggers the creation of a TextEdit record to hold the characters you type while
- // the user sees bullet points on the screen. The TE record is created by the first call to SetEditFieldInfo
- // with the flag set. This method then sets the <editFieldHCMirrorAlloc> flag, to indicate that a TextEdit
- // record was created. Subsequent calls to SetEditFieldInfo() won't create more records as long as this flag
- // is set. You can use GetValueAsText() to retrieve the true data from a password field. Pasting into such
- // a field is prevented, and cutting or copying from the field copies the bullet points- you can only get
- // the true data programmatically, which is how it should be. NEVER set the <editFieldHCMirrorAlloc> flag
- // yourself or in the resource, or things will quickly die.
-
- // 'ictb' parsing stuff:
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=mac68k
- #endif
-
- // first part of resource is array of these:
-
- typedef struct
- {
- unsigned short iData; // item data flags (enumerated below)
- unsigned short iOffset; // offset to data table
- }
- ictbItemEntry, *ictbPtr, **ictbHandle;
-
- // text info stored in tables like this:
-
- typedef struct
- {
- short txtFont; // font ID or offset to name
- Style txtFace; // face- plain, bold, etc
- char filler;
- short txtSize; // font size
- RGBColor txtFColour; // text colour
- RGBColor txtBColour; // background colour
- short txtMode; // transfer mode
- }
- ictbTextStyleTable, *ictbTablePtr;
-
- // iData is bitfield arranged thus:
-
- enum
- {
- fFamChange = 1, // change the font
- fFaceChange = 2, // change the face
- fSizeChange = 4, // change the size
- fFColourChange = 8, // change the colour
- fAddFontSize = 16, // add the size
- fBColourChange = 8192, // change the background colour
- fModeChange = 16384, // change the mode
- fIsFNameOffset = 32768 // txtFont is offset to font name
- };
-
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=reset
- #endif
-
- // message sent to dialog's boss when dialog closed OK. You can listen for this
- // so that you get informed when the user closes the dialog. The boss listens for
- // this anyway- you just need to override ReceiveMessage to take action.
-
- enum
- {
- kMsgDialogSuccessfullyClosed = 'dlg$',
- kMsgDialogCancelled = 'dlg-',
- kMsgDialogItemClicked = 'dlg~',
- kMsgDialogSetUp = 'dlg!'
- };
-
- // set up streaming stuff:
-
- DEFINECLASSID( ZDialog, 'zdlg' );
-
-
- // class definition
-
- class ZDialog : public ZWindow
- {
- protected:
- Boolean isModal; // TRUE if dialog is modal
- Boolean isInline; // Dialog being handled by RunModal()- caller deletes.
- DItemInfoHdl dItemInfo; // extra info about dialog items
- ictbHandle ictb; // local handle to ictb resource, if any
- short signalDismiss; // set to ok or cancel to close dialog safely in response to messages
- short exitItem; // set to the item that dismissed the dialog, used by RunModal().
- short baseItems; // count of "native" items in the dialog
-
- public:
-
- ZDialog( ZCommander* aBoss, const short dialogID );
- ZDialog();
- virtual ~ZDialog();
-
- // window handling stuff
-
- virtual void InitZWindow();
- virtual void Draw();
- virtual Boolean Close(const short phase);
- virtual void AdjustCursor(const Point mouse, const short modifiers);
- virtual void Click( const Point mouse, const short modifiers );
- virtual void Activate();
- virtual void Deactivate();
- virtual void Idle();
- virtual void Type( const char theKey, const short modifiers );
-
- // command stuff
-
- virtual void UpdateMenus();
-
- // std edit commands
-
- virtual Boolean CanPasteType();
- virtual void DoCut();
- virtual void DoCopy();
- virtual void DoPaste();
- virtual void DoClear();
- virtual void DoSelectAll();
-
- // dialog handling stuff
-
- virtual void SetUp();
- virtual void ClickItem( const short theItem );
- virtual Boolean CloseDialog();
- virtual Boolean Filter( EventRecord* theEvent );
- virtual void DrawUserItem( const short item );
- virtual void DrawOneItem( const short item );
- virtual void SetDialogBaseFont( short fontID = 0, short fontSize = 12, short fontStyle = 0 );
-
- // convenience functions
-
- virtual void SetValue( const short item, const long value );
- virtual void SetValue( const short item, const int value ) { SetValue(item, (long) value); }
- virtual void SetValue( const short item, const short value ) { SetValue(item, (long) value); }
- virtual void SetValue( const short item, const Str255 value );
- virtual void SetValue( const short item, const double value );
- virtual void SetValue( const short item, const float value ) { SetValue(item, (double) value); }
-
- virtual long GetValue( const short item );
- virtual void GetValueAsText( const short item, Str255 aStr );
- virtual float GetValueAsFloat( const short item );
-
- virtual short GetSelectedItemInGroup( const short groupID );
-
- // info about dialog items:
-
- virtual void GetItemBounds( const short item, Rect* bounds );
- virtual short GetItemType( const short item );
- virtual short FindItem( const Point localMouse );
- virtual void FakeClick( const short item );
- virtual Boolean HasEditFields();
- virtual Boolean ValidateItem( const short item, Boolean showAlert = FALSE );
-
- // manipulating items' appearance and behaviour:
-
- virtual void HiliteItem( const short item, const short state );
- virtual void OutlineDefaultItem();
- virtual void HideItem( const short item );
- virtual void ShowItem( const short item );
- virtual void EnableItem( const short item );
- virtual void DisableItem( const short item );
- virtual void SetEditFieldInfo( const short item, unsigned short iFlags, long iMin = 0, long iMax = 0 );
- virtual void GetEditFieldInfo( const short item, unsigned short* iFlags, long* iMin = NULL, long* iMax = NULL );
- virtual void SetItemTitle( const short item, Str255 title );
- virtual void SelectItem( const short item );
-
- // multi-part dialogs:
-
- virtual void AppendItemsToDialog( const short ditlID, DITLMethod apMethod = overlayDITL );
- virtual void RemoveAppendedItems();
- inline short GetBaseItemCount() { return baseItems; };
-
- // streaming:
-
- virtual void WriteToStream( ZStream* aStream );
- virtual void ReadFromStream( ZStream* aStream );
-
- // d+d:
-
- virtual Boolean AcceptsFlavour( const OSType aFlavour ) { return FALSE; };
-
- inline Boolean IsModal() { return isModal; };
-
- // convenience method for implementing "inline" modal dialogs- use with care!
-
- virtual Boolean RunModal();
-
- // force modal dialog session to end. Very rarely needed or used.
-
- virtual void DismissModal( const short itemDismiss );
-
- // ictb stuff:
-
- virtual void SetTEItemDataFromIctb( const short teItem, Boolean applyChanges = TRUE );
-
- protected:
-
- virtual void MakeMacWindow( const short dialogID );
- virtual void MakeMacWindow( Rect* aRect, Str255 title, Boolean visible = FALSE, short varCode = 0, Boolean hasCloseBox = FALSE, void* userData = NULL );
-
- virtual void SetUpUserItems( short fromItemNo = 0 );
- virtual void SetUpRadioGroups( short fromItemNo = 0 );
- virtual void ParseRButtonTitle( Str255 buttonTitle, short* groupID, Boolean* isDefault );
- virtual void HandleRButtonGroupClick( const short item );
-
- virtual void AddGreyscaleEffects();
- virtual void ClearDITLPlaceHolders( Handle ditl );
-
- // key and paste data filtering methods, used in conjunction with edit field info:
-
- virtual Boolean KeyIsLegal( char* theKey, const short targetItem );
- virtual Boolean PasteDataIsLegal( const short targetItem );
-
- // set up method for edit fields from resources
-
- virtual void ParseEditFieldInfo( Str255 efText, unsigned short* efFlags, long* min, long* max );
- };
-
- /*
-
- This is a ZWindow that manages a modal or modeless dialog using the dialog manager. For specific
- dialogs, you need to override the SetUp, ClickItem and CloseDialog methods to handle your par-
- ticular items. The rest is done for you.
-
- Though ZDialog is built upon the Dialog Manager, it extends the feature set of dialogs which make them
- much easier to use than the "bare" DM.
- */
-
- // method to convert real numbers to strings
-
- void RealToString( const double num, Str255& str, short decPlaces = 3 );
-
- // compiler flags:
-
- // this class can now provide some support for the Apple Grayscale Appearance. If you do not want this
- // additional support ( which draws 3D borders around edit fields and list boxes and draws user items as
- // a 3D embossed line ), comment out the following compiler flag
-
- #define _GREYSCALE_APPEARANCE 1
-
- // static function for drawing 3D effect rectangles:
-
- void FrameGrayRect( Rect* aRect );
-
- #define kFieldRangeAlertID 137
-
- #endif